# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models, _

import datetime



import logging
_logger = logging.getLogger(__name__)

class CrEmpTolerate(models.Model):

    _name = "cr.emp.tolerate"
    _description = "容错"

    name = fields.Char(string='姓名',related='staff_id.name',store=True)
    card_id = fields.Char(string='工号',related='staff_id.card_id',store=True)
    ws_id = fields.Many2one('cr.emp.workshop', string='所属车间', related='staff_id.ws_id',store=True)
    team_id = fields.Many2one("cr.emp.team", string='班组', related='staff_id.team_id',store=True)
    post_id = fields.Many2one("cr.emp.post", string='岗位', related='staff_id.post_id',store=True)
    staff_id = fields.Many2one('cr.emp.staff',string='员工')

    fault_type_id = fields.Many2one('cr.emp.fault.type',string='问题分类',)
    fault_nature_type = fields.Selection([
        ('self', '自我暴露'),
        ('other', '他人指出'),
        ('check', '检查发现')], string= '问题性质类别')
    fault_nature_id = fields.Many2many('cr.emp.fault.nature',string='问题性质')
    time = fields.Datetime(string='发生时间')

    year = fields.Char(string='年份',compute='_compute_time',store=True)
    month = fields.Char(string='月份',compute='_compute_time',store=True)

    @api.depends('time')
    def _compute_time(self):
        for i in self:
            if i.time:
                i.year=i.time.year
                i.month=i.time.month

class CrEmpCorrect(models.Model):
    _name = "cr.emp.correct"
    _description = "纠错"

    name = fields.Char(string='姓名', related='staff_id.name',store=True)
    card_id = fields.Char(string='工号', related='staff_id.card_id',store=True)
    ws_id = fields.Many2one('cr.emp.workshop', string='所属车间', related='staff_id.ws_id',store=True)
    team_id = fields.Many2one("cr.emp.team", string='班组', related='staff_id.team_id',store=True)
    post_id = fields.Many2one("cr.emp.post", string='岗位', related='staff_id.post_id',store=True)
    staff_id = fields.Many2one('cr.emp.staff', string='员工')

    handle_num = fields.Integer(string='得牌数')
    observe_time = fields.Char(string='观察期止')
    is_stop = fields.Boolean(string='是否中止')
    time = fields.Datetime(string='记录时间')

    year = fields.Char(string='年份',compute='_compute_time',store=True)
    month = fields.Char(string='月份',compute='_compute_time',store=True)

    @api.depends('time')
    def _compute_time(self):
        for i in self:
            if i.time:
                i.year=i.time.year
                i.month=i.time.month